import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'
import CustomerMgr from '@/biz/customer/customerOpt.js'
import pointMgr from '@/biz/customerForCode/point'

let _this = null
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'pointPositionName',
        minWidth: 200,
        title: '点位名'
      },
      {
        title: '参与人数',
        field: 'joinUserNum',
        minWidth: 150
      },
      {
        title: '扫码数',
        field: 'visitsNum',
        minWidth: 150
      },
      {
        title: '新增线索客户',
        field: 'newClues',
        minWidth: 150
      },
      {
        title: '线索转到访',
        field: 'visitCustomer',
        minWidth: 150
      },
      {
        title: '签订',
        field: 'signCustomer',
        minWidth: 150
      },
      {
        title: '创建人员',
        field: 'userName',
        minWidth: 150,
        cell: {
          value: (rows) => {
            return `${rows.userName ? rows.userName : '-'}${rows.workNo ? '(' + rows.workNo + ')' : ''}`
          },
          text: {}
        }
      },
      {
        title: '创建时间',
        field: 'createTime',
        minWidth: 150
      },
      {
        title: '操作',
        fixed: 'right',
        minWidth: 240,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: '详情',
              event: 'checkFun',
              data: params.row
            })

            btns.push({
              title: params.row.defaultDataFlag == 0 ? '编辑' : '',
              event: 'editFun',
              data: params.row
            })
            btns.push({
              title: '下载拓客码',
              event: 'downloadFun',
              data: params.row
            })
            btns.push({
              title: params.row.delFlag ? '删除' : '',
              event: 'delFun',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

class activityColumn extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'tokerName',
        minWidth: 200,
        title: '拓客码名',
        header: {
          filter: {
            title: '拓客码名',
            key: 'tokerId',
            placeholder: '请选择拓客码名',
            load: (o) => {
              pointMgr.getTokerAndChannelList({ id: _this.$route.query.activityId }).then((res) => {
                res &&
                  res.forEach((item) => {
                    item.key = item.tokerId
                    item.value = item.tokerName
                  })
                o.select.options = res
              })
            },
            select: {
              options: []
            }
          }
        }
      },
      {
        field: 'channelName',
        minWidth: 200,
        title: '渠道'
      },
      {
        field: 'pointPositionName',
        minWidth: 200,
        title: '点位名'
      },
      {
        title: '参与人数',
        field: 'joinUserNum',
        minWidth: 150,
        slots: {
          default: (params, h) => {
            return table.cell.btn(_this, h, {
              title: params.row.joinUserNum,
              event: 'taskInfun',
              data: params.row
            })
          }
        }
      },
      {
        title: '创建人员',
        field: 'userName',
        minWidth: 150,
        cell: {
          value: (rows) => {
            return `${rows.userName}${rows.workNo ? '(' + rows.workNo + ')' : ''}`
          },
          text: {}
        }
      },
      {
        title: '创建时间',
        field: 'createTime',
        minWidth: 150
      },
      {
        title: '操作',
        fixed: 'right',
        minWidth: 320,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = []
            btns.push({
              title: '下载拓客码',
              event: 'downloadFun',
              data: params.row
            })
            btns.push({
              title: '编辑拓客码',
              event: 'addExpandCode',
              data: params.row
            })
            btns.push({
              title: params.row.defaultDataFlag == 0 ? '编辑点位' : '',
              event: 'editFun',
              data: params.row
            })
            btns.push({
              title: params.row.delFlag ? '删除' : '',
              event: 'delFun',
              data: params.row
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

class detailColumn extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'userName',
        minWidth: 200,
        title: '拓客人员',
        cell: {
          value: (rows) => {
            return `${rows.userName}${rows.workNo ? '(' + rows.workNo + ')' : ''}`
          },
          text: {}
        }
      },
      {
        title: '扫码数',
        field: 'visitsNum',
        minWidth: 150
      },
      {
        title: '新增线索客户',
        field: 'newClues',
        minWidth: 150
      },
      {
        title: '线索转到访',
        field: 'visitCustomer',
        minWidth: 150
      },
      {
        title: '签订',
        field: 'signCustomer',
        minWidth: 150
      }
    ]
  }
}

class pointDetailColumn extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'userName',
        minWidth: 120,
        title: '拓客人员',
        cell: {
          value: (rows) => {
            return `${rows.userName}${rows.workNo ? '(' + rows.workNo + ')' : ''}`
          },
          text: {}
        }
      },
      {
        field: 'visitsNum',
        minWidth: 120,
        title: '扫码数'
      },
      {
        field: 'newClues',
        minWidth: 120,
        title: '新增线索'
      },
      {
        field: 'visitCustomer',
        minWidth: 120,
        title: '线索转到访'
      },
      {
        field: 'signCustomer',
        minWidth: 120,
        title: '签订'
      }
    ]
  }
}
export default { Column, activityColumn, detailColumn, pointDetailColumn }
